package dream_scene

import (
	"go_server/game_server/api/service"
	"go_server/game_server/event_manager"
	"go_server/game_server/event_manager/event_data"
	"go_server/zinx/zlog"
)

type DreamSceneService struct {
	service.AbsService
	GetDreamSceneList      *GetDreamSceneListApi
	DreamSceneBattle       *DreamSceneBattleApi
	DreamSceneMopUp        *DreamSceneMopUpApi
	GetDreamSceneBoxStates *GetDreamSceneBoxStatesApi
	GetDreamSceneBoxPrize  *GetDreamSceneBoxPrizeApi

	eventMethods map[event_data.EventType]func(event event_data.IEvent)
}

const (
	DREAM_SCENE_EVENT_TYPE        = 2        // 梦境战斗场景类型
	DREAM_SCENE_POWER_ID          = 51210041 // 体力道具id
	DREAM_SCENE_FIRST_SCENE_Id    = 13010001 // 梦境第一关关卡id,初始化激活
	DREAM_SCENE_REGISTER_SCENE_Id = 13110001 // 新手战斗
)

var (
	ServiceObj *DreamSceneService
)

func init() {
	ServiceObj = &DreamSceneService{
		GetDreamSceneList:      &GetDreamSceneListApi{},
		DreamSceneBattle:       &DreamSceneBattleApi{},
		DreamSceneMopUp:        &DreamSceneMopUpApi{},
		GetDreamSceneBoxStates: &GetDreamSceneBoxStatesApi{},
		GetDreamSceneBoxPrize:  &GetDreamSceneBoxPrizeApi{},

		eventMethods: make(map[event_data.EventType]func(event event_data.IEvent)),
	}

	event_manager.EventManagerObj.AddServiceEvent(event_data.LoginEvent, onLoginEvent, ServiceObj) //监听登录事件，测试

}

func (s *DreamSceneService) GetModuleName() string {
	return "dream_scene"
}

func (s *DreamSceneService) GetEventHandleFunc(eventType event_data.EventType) (func(event event_data.IEvent), bool) {
	eventFunc, ok := s.eventMethods[eventType]
	if !ok {
		zlog.Errorf("GetEventHandleFunc Err!!! method not found!! eventType: %d", eventType)
		return nil, false
	}
	return eventFunc, true
}

func (s *DreamSceneService) GetEventMap() map[event_data.EventType]func(event event_data.IEvent) {
	return s.eventMethods
}

func onLoginEvent(event event_data.IEvent) {
	/*conn := event.GetRoleConn()
	roleId, ok := event.GetRoleId()
	if !ok {
		return
	}

	ServiceObj.GetDreamSceneBoxStates.TestHandle(roleId, conn)
	ServiceObj.GetDreamSceneBoxPrize.TestHandle(roleId, conn)
	ServiceObj.GetDreamSceneBoxStates.TestHandle(roleId, conn)*/
}
